from threading import Thread
import time
import os
def func(name):
    for i in range(10):
        time.sleep(1)
        print(name,i,f'当前进程为{os.getpid()},父进程为{os.getppid()}')


if __name__ == '__main__':
    #创建线程
    t1 = Thread(target=func,args=('刘秀',))
    t2 = Thread(target=func,args=('赵匡胤',))
    t3 = Thread(target=func,args=('李世民',))

    t1.start()
    t2.start()
    t3.start()


class MyThread(Thread):
    def __init__(self,name):
        super(MyThread,self).__init__()
        self.name=name
    def run(self):
        for i in range(10):
            time.sleep(1)
            print(self.name,i,f'当前进程为{os.getpid()},父进程为{os.getppid()}')


if __name__ == '__main__':
    #创建线程
    t1 = MyThread('刘秀22')
    t2 = MyThread('赵匡胤33')
    t3 = MyThread('李世民444')

    # t1.start()
    # t2.start()
    # t3.start()

